package thread;

public class ThreadDemo10 {
    public static void main(String[] args) {
        Thread t = new Thread(()->{
            for (int i = 0; i < 3; i++) {
                System.out.println("hello");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        t.start();

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("join之前");
        /**join 有三个版本
         *  1.无参 就是死等 容易出现问题
         *  2.设置一个最大等待时间
         */

        try {
            //join之前 t的run方法就结束了 就不会等待了
            t.join();//主线程等待t的run方法执行完 (阻塞)
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("join之后");
    }
}
